<?php

class FV_NiveauConfiance extends FormulaireValidatorImpl{

	public function __construct(){
		$this->levelRequis = 3;
		$this->messageEchec =  'Compléxite insufisante';
	}
	
	public function getMessage($level){
		
		$message = null;
		
		if($level <= 2){
			$message = $this->messageEchec;
		}else if($level == 3){
			$message = 'Compléxite moyenne';
		}else{
			$message = 'Compléxite forte';
		}
		
		return $message;
	}
	

	public function test($value){
		
		$strongness = 0;
		
		$regex="/[A-Z]/"; //regular expression
		if (preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[a-z]/";		
		if (preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[0-9]/";		
		if (preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[\W_]/"; //special characters and underscore character
		if (preg_match($regex,$value)){ 
			$strongness++;			 
		}
		
		
		return $strongness;
	}
	
}